package com.zx.mes.rabbitmq.hyl.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Topic Exchange
 * 对topic规则配置，这里使用两个队列来测试
 * @author hyl
 * @date 2018-3-19
 */
@Configuration
public class TopicRabbitConfig {

    private static final String TOPIC_MESSAGE="topic.message";
    private static final String TOPIC_MESSAGES = "topic.messages";

    private static final String EXCHANGE_NAME_TOPIC_EXCHANGE = "topicExchange";

    private static final String ROUTING_KEY_TOPIC_MESSAGE = "topic.message";
    private static final String ROUTING_KEY_TOPIC_MESSAGES = "topic.#";

    @Bean
    public Queue queueMessage(){
        return new Queue(TOPIC_MESSAGE);
    }

    @Bean
    public Queue queueMessages(){
        return new Queue(TOPIC_MESSAGES);
    }

    @Bean
    TopicExchange exchange(){
        return new TopicExchange(EXCHANGE_NAME_TOPIC_EXCHANGE);
    }

    @Bean
    Binding bindingExchangeMessage(Queue queueMessage,TopicExchange exchange){
        return BindingBuilder.bind(queueMessage).to(exchange).with(ROUTING_KEY_TOPIC_MESSAGE);
    }

    @Bean
    Binding bindingExchangeMessages(Queue queueMessages,TopicExchange exchange){

        return BindingBuilder.bind(queueMessages).to(exchange).with(ROUTING_KEY_TOPIC_MESSAGES);
    }

}
